package ui;

import dbreflection.tablemanagement.DatabaseObject;
import ui.components.JJTable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;

/**
 * Created by IntelliJ IDEA.
 * User: [J0k3r]
 * Date: 14.11.2008
 * Time: 15:43:18
 */
public class TableFrame extends JDialog {
    private JJTable tab = new JJTable();
    private static DatabaseObject value = null;
    public TableFrame(String table) throws SQLException {
        this.setModal(true);

        final NomenclatureSelecter ns = new NomenclatureSelecter();
        this.getContentPane().add(new JScrollPane(ns), BorderLayout.CENTER);

        JPanel butPan = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
        ((JButton)butPan.add(new JButton("OK"))).addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                value = (DatabaseObject) ns.getKey(ns.getSelectedRow());
                TableFrame.this.dispose();
            }
        });

        this.getContentPane().add(butPan, BorderLayout.SOUTH);
        this.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        this.pack();
        this.setVisible(true);
    }

    public static DatabaseObject getValue() {
        return value;
    }
}
